<template>
  <div>
    <el-form>
      <el-row :gutter="24">

        <el-col :span="12">
          <el-form-item>
            <el-input></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item>
            <el-button type="primary">
              查询
            </el-button>

            <el-button type="primary" @click="add()">
              增加
            </el-button>

          </el-form-item>
        </el-col>

      </el-row>


    </el-form>
    <!--表格内容-->
    <el-table ref="orderList" :data="tableData" style="width: 100%;margin-bottom: 5px;" border stripe highlight-current-row>
      <!-- v-for="item in tableData" v-bind:key="item.index" -->
      <el-table-column fixed type="selection" width="45">
      </el-table-column>
      <el-table-column property="menuName" label="菜单名称" align="center">
      </el-table-column>
      <el-table-column property="groupTitle" label="分组标题" align="center">
      </el-table-column>
      <el-table-column property="link" label="链接" align="center">
      </el-table-column>
      <el-table-column property="icon" label="图表" align="center">
      </el-table-column>
      <el-table-column property="visible" label="可见性" align="center">
      </el-table-column>
      <el-table-column property="rank" label="级别" align="center">
      </el-table-column>
      <el-table-column property="previousId" label="上级菜单ID" align="center">
      </el-table-column>
      <el-table-column property="number" label="顺序" align="center">
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center">
        <template slot-scope="scope">
          <el-button circle icon="el-icon-edit-outline" type="primary" @click="Compile()" title="编辑" size="small">
          </el-button>
          <el-button circle icon="el-icon-delete" type="danger" title="删除" size="small"
            @click="rowDel(scope.$index, scope.row, $event)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination :page-sizes="[10, 20, 30, 40, 100]" :page-size="10" :total="100"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <Add v-if="isShowAddDialog" :isShowAddDialog="isShowAddDialog" @dialogClose="dialogClose"></Add>
    <Compile v-if="isShowComDialog" :isShowComDialog="isShowComDialog" @dialogClose="dialogClose"></Compile>
  </div>
</template>
   
<script>
import Add from "./orderManageAdd.vue";
import Compile from "./orderManagecomple.vue";

export default {
  name: "orderManage",
  components: {
    Add,
    Compile,
  },
  data() {
    return {
      formFileds: {
      },
      tableData: [
        {
          index: 0,
          menuName: "用户管理",
          groupTitle: '',
          link: '',
          icon: '',
          visible: '',
          rank: "一级",
          previousId: "",
          number: "2",
        },  
      ],
      isShowAddDialog:false,
      isShowComDialog:false,
    }
  },
  methods: {
    rowEdit(row) {
      // //当前选中行
      this.formFileds = row;
    },
    dialogClose() {

      this.isShowAddDialog = false;
      this.isShowComDialog = false;
    },
    handleEdit(id) {
      this.$refs.editForm.validate(isValid => {

        if (!isValid) return;

        // 保存编辑后的数据
        Object.assign(this.tableData[id], this.formFileds);
        this.isShowEditDialog = false;

        // 考虑到可能编辑了日期-需要重新排序
        // ***注意：手动排序传参和表格的default-sort属性格式不太一样
        this.$refs.list.sort('date', 'descending');

        this.$message.success('编辑成功');
      });
    },
    add() {
      this.isShowAddDialog = true;
    },
    Compile() {
      this.isShowComDialog = true;
    },
    
    rowDel(row, event) {

      // 让当前删除按钮失焦
      event.target.blur();

      this.$confirm('确定要删除当前行吗？', '删除', {
        comfirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {

        this.tableData.splice(row.id, 1);
        this.$message.success('删除成功');
        return false;
      });
    },
    // 选中当前行-当前行的复选框被勾选
    setCurRowChecked(row) {

      this.$refs.orderList.clearSelection();
      this.$refs.orderList.toggleRowSelection(row);
    }
  }
}
</script>
  
<style scoped lang="less">
.el-form {
  padding: 0 10px;
}

.el-date-editor {
  width: 100% !important;
}
</style>
  